package Dg;

import java.util.ArrayList;
import java.util.Scanner;

public class KTV {
    public KTV() {
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Music> list = new ArrayList();

        while(true) {
            System.out.println("---------------欢迎使用点歌系统---------------");
            System.out.println("1.添加歌曲至列表");
            System.out.println("2.将歌曲置顶");
            System.out.println("3.将歌曲前一位");
            System.out.println("4.退出");
            System.out.println("5.查看歌曲列表");
            System.out.println("6.删除歌曲");
            switch (sc.next()) {
                case "1":
                    AddTo(list);
                    break;
                case "2":
                    Top(list);
                    break;
                case "3":
                    InAdvance(list);
                    break;
                case "4":
                    System.out.println("退出");
                    System.exit(0);
                    break;
                case "5":
                    View(list);
                    break;
                case "6":
                    Delete(list);
                    break;
                default:
                    System.out.println("没有这个选项");
            }
        }
    }

    public static void AddTo(ArrayList<Music> list) {
        Scanner sc = new Scanner(System.in);
        Music a = new Music();
        System.out.println("请输入你需要添加的歌曲名");
        String name = sc.nextLine();
        a.setName(name);
        list.add(a);
    }

    public static void View(ArrayList<Music> list) {
        new Scanner(System.in);
        if (list.size() == 0) {
            System.out.println("当前还未有歌曲");
        } else {
            for(int i = 0; i < list.size(); ++i) {
                Music a = (Music)list.get(i);
                int c = i + 1;
                System.out.println("" + c + ":" + a.getName());
            }
        }

    }

    public static void Top(ArrayList<Music> list) {
        Scanner sc = new Scanner(System.in);
        if (list.size() == 0) {
            System.out.println("当前还未有歌曲");
        } else {
            System.out.println("请输入需要置顶的歌曲名");
            String a = sc.nextLine();

            for(int i = 0; i < list.size(); ++i) {
                Music b = (Music)list.get(i);
                if (a.equals(b.getName())) {
                    list.remove(i);
                    list.add(0, b);
                    break;
                }

                if (a == b.getName()) {
                    System.out.println("为查询到你想要置顶的歌曲");
                    break;
                }
            }
        }

    }

    public static void Delete(ArrayList<Music> list) {
        Scanner sc = new Scanner(System.in);
        if (list.size() == 0) {
            System.out.println("当前还未有歌曲");
        } else {
            System.out.println("请输入想要删除的歌名");
            String a = sc.nextLine();
            int i = 0;
            if (i < list.size()) {
                Music b = (Music)list.get(i);
                if (b.getName().equals(a)) {
                    list.remove(i);
                } else {
                    System.out.println("为查询到你想要删除的歌曲");
                }
            }
        }

    }

    public static void InAdvance(ArrayList<Music> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入需要提前一位的歌曲名");
        String a = sc.nextLine();

        for(int i = 0; i < list.size(); ++i) {
            Music b = (Music)list.get(i);
            if (b.getName().equals(a)) {
                if (i > 0) {
                    list.add(i - 1, b);
                    list.remove(i + 1);
                    System.out.println("操作成功");
                    break;
                }

                if (i <= 0) {
                    System.out.println("已是第一位");
                }
            } else if (b.getName() == a) {
                System.out.println("歌曲不存在或已是置顶");
            }
        }

    }
}
